package cn.iocoder.yudao.module.member.dal.mysql.memberconf.confrebate;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.member.controller.admin.confrebate.vo.MemberConfRebatePageReqVO;
import cn.iocoder.yudao.module.member.dal.dataobject.memberconf.confrebate.MemberConfRebateDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 返佣政策配置 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface MemberConfRebateMapper extends BaseMapperX<MemberConfRebateDO> {

    default PageResult<MemberConfRebateDO> selectPage(MemberConfRebatePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MemberConfRebateDO>()
                .eqIfPresent(MemberConfRebateDO::getMaterialPolicyId, reqVO.getMaterialPolicyId())
                .eqIfPresent(MemberConfRebateDO::getRebateType, reqVO.getRebateType())
                .eqIfPresent(MemberConfRebateDO::getActionType, reqVO.getActionType())
                .eqIfPresent(MemberConfRebateDO::getPerQuantity, reqVO.getPerQuantity())
                .eqIfPresent(MemberConfRebateDO::getRebatePoints, reqVO.getRebatePoints())
                .orderByDesc(MemberConfRebateDO::getId));
    }

    default List<MemberConfRebateDO> selectListByMaterialPolicyId(Long materialPolicyId) {
        return selectList(MemberConfRebateDO::getMaterialPolicyId, materialPolicyId);
    }

    default List<MemberConfRebateDO> selectListByMaterialPolicyIds(List<Long> materialPolicyIds) {
        return selectList(new LambdaQueryWrapperX<MemberConfRebateDO>()
                .in(MemberConfRebateDO::getMaterialPolicyId, materialPolicyIds));
    }

    default int deleteByMaterialPolicyId(Long materialPolicyId) {
        return delete(MemberConfRebateDO::getMaterialPolicyId, materialPolicyId);
    }
}
